package com.edu.exam.enums.curriculum;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 选课状态枚举
 *
 * @author System
 * @version 1.0.0
 * @since 2025-11-14
 */
public enum SelectionStatus implements BaseEnum {
    PENDING("PENDING", "待确认"),
    CONFIRMED("CONFIRMED", "已确认"),
    ACTIVE("ACTIVE", "生效中"),
    COMPLETED("COMPLETED", "已完成"),
    WITHDRAWN("WITHDRAWN", "已退课"),
    REJECTED("REJECTED", "被拒绝"),
    CANCELLED("CANCELLED", "已取消");

    private final String code;
    private final String description;

    SelectionStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果编码无效
     */
    public static SelectionStatus fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Selection status code cannot be null or empty");
        }

        for (SelectionStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown selection status code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static SelectionStatus fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("Selection status description cannot be null or empty");
        }

        for (SelectionStatus status : values()) {
            if (status.getDescription().equals(description)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown selection status description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}